<?php

if (!defined('BASEPATH'))
exit('No direct script access allowed');

class Events extends MX_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 * 	- or -
	 * 		http://example.com/index.php/welcome/index
	 * 	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	function Events() {
		parent::__construct();
		$this->load->model('lookupmodel');
		$this->load->model('helpermodel');
		//check is logged in
		$this->load->model('languagemodel');
		$this->load->model('projects/mdl_projectsmodel');
		$this->language = $this->languagemodel->is_language_using();
		$this->load->helper('MY_url_helper');
		$this->load->helper('text');
		
		$this->load->model('banners/bannermodel');
	}

	public function index() {
		$this->lang->load('events/events', $this->language);

		//SEO
		$data['title'] = $this->lang->line('events_text_title');
		$data['description'] = $this->lang->line('events_text_description');
		$data['keywords'] = $this->lang->line('events_text_keywords');

		$data['breadcrumbs'] = array();

		$data['breadcrumbs'][] = array(
			'text'      => '',
			'href'      => base_url()
		);

		$data['breadcrumbs'][] = array(
			'text'      => $this->lang->line('text_heading'),
			'href'      => base_url() . 'events-calendar.html'
		);

		//get all event
		$this->load->model('mdl_events');
		//set event id is default value
		$id = 0;
		$results = $this->mdl_events->getEvents($id, $this->config->item('config_language_id'), $this->config->item('market'));
		$data['events'] = array();
		if($results) {
			foreach ($results as $result) {
				$eventsMedia = $this->mdl_events->getEventsImage($result->Event_ID);
				if($eventsMedia) {
					$imageUrl = $this->config->item('HTTP_EVENT_MEDIA_IMAGE') . $eventsMedia[0]->FileName . '-120x70' . $eventsMedia[0]->Extension;
				} else {
					$imageUrl = $this->config->item('HTTP_IMAGE') . 'photos/calendar-default.jpg';
				}
					
				$data['events'][] = array(
					'Event_ID'	=> $result->Event_ID,
					'Title'		=> $result->Title,
					'Summary'	=> $result->Summary,
					'StartDate'	=> $result->StartDate,
					'StartTime'	=> $result->StartTime,
					'EndDate'	=> $result->EndDate,
					'EndTime'	=> $result->EndTime,
					'Cover'		=> $imageUrl,
				);
			}
		}
		
		//get banner for right side
		$data['banner'] = $this->bannermodel->getBanners('Event', $this->config->item('market'), $this->config->item('config_language_id'));

		$data['module'] = "events";
		$data['view_file'] = "events";

		echo Modules::run('template/default_template', $data);
	}
	public function detail() {
		$this->lang->load('events/detail', $this->language);

		//SEO
		$data['title'] = $this->lang->line('events_text_title');
		$data['description'] = $this->lang->line('events_text_description');
		$data['keywords'] = $this->lang->line('events_text_keywords');

		$data['breadcrumbs'] = array();

		$data['breadcrumbs'][] = array(
			'text'      => '',
			'href'      => base_url()
		);

		$data['breadcrumbs'][] = array(
			'text'      => $this->lang->line('text_heading'),
			'href'      => base_url() . 'events-calendar.html'
		);

		$id = $this->uri->segment(3);

		//get all event
		$this->load->model('mdl_events');
		$result = $this->mdl_events->getEvents($id, $this->config->item('config_language_id'), $this->config->item('market'));
		$data['events'] = array();
		if($result) {
			//get Event Media by Id
			$eventsMedia = $this->mdl_events->getEventsImage($id);
			$data['events'] = array(
				'Event_ID'	=> $result->Event_ID,
				'Title'		=> $result->Title,
				'Summary'	=> $result->Summary,
				'Description'	=> $result->Description,
				'Venue'		=> $result->Venue,
				'Email'		=> $result->Email,
				'StartDate'	=> $result->StartDate,
				'StartTime'	=> $result->StartTime,
				'EndDate'	=> $result->EndDate,
				'EndTime'	=> $result->EndTime,
				'eventsMedia'=> $eventsMedia
			);
		} else {
			redirect(base_url() . 'error_404', 'refresh');
		}

		$data['breadcrumbs'][] = array(
			'text'      => $data['events']['Title'],
			'href'      => base_url() . 'events/detail/' . $id
		);
		
		//get banner for right side
		$data['banner'] = $this->bannermodel->getBanners('Event', $this->config->item('market'), $this->config->item('config_language_id'));

		$data['module'] = "events";
		$data['view_file'] = "detail";

		echo Modules::run('template/default_template', $data);
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */